package com.some;

import java.util.Scanner;

public class NetEasy3 {

    int min = Integer.MAX_VALUE;
    int[][] go = {{1, 0}, {0, 1}};

    //flag为0则上一个为平地，flag为1则上一个为沼泽
    public int findTime(int[][] num, int startX, int startY, int sum) {
        if (startX == num.length - 1 && startY == num[0].length - 1) {
            min = Math.min(min, sum);
            return min;
        }
        if (startX > num.length - 1 || startY > num[0].length - 1 || startX < 0 || startY < 0) {
            return min;
        }
        int cur = num[startX][startY];
        for (int x = 0; x < 2; x++) {
            int newX = go[x][0] + startX;
            int newY = go[x][1] + startY;
            if (newX < num.length && newY < num[0].length) {
                if (cur == num[newX][newY]) {
                    sum = sum + 1;
                } else {
                    sum = sum + 2;
                }
                findTime(num, newX, newY, sum);
                //回溯
                startX = newX - go[x][0];
                startY = newY - go[x][1];
                if (cur == num[newX][newY]) {
                    sum = sum - 1;
                } else {
                    sum = sum - 2;
                }
            }
        }
        return min;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 沼泽长度
        int a = scanner.nextInt();
        // 沼泽宽度
        int b = scanner.nextInt();
        int[][] ints = new int[a][b];
        // 构造沼泽
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                ints[i][j] = scanner.nextInt();
            }
        }
        NetEasy3 netEasy = new NetEasy3();
        System.out.println(netEasy.findTime(ints, 0, 0, 0));
    }
}
